﻿@model string

@{ 
    string fullImageUrl = string.Empty;
    string mediaFolder = Convert.ToString(ViewData.ModelMetadata.AdditionalValues["MediaFolder"]);
    string isImage = ViewData.ModelMetadata.AdditionalValues.ContainsKey("IsImage")
        ? Convert.ToString(ViewData.ModelMetadata.AdditionalValues["IsImage"])
        : "true";
    bool hasPreview = ViewData.ModelMetadata.AdditionalValues.ContainsKey("FullImageUrl");

    if (hasPreview)
    {
        fullImageUrl = Convert.ToString(ViewData.ModelMetadata.AdditionalValues["FullImageUrl"]);
    } 
}

<div class="sale-setup-label-container">@Html.LabelFor(m => m)</div>
<div class="sale-setup-input-container">
    @Html.TextBoxFor(m => m,
        new Dictionary<string, object> {
            { "data-bind", "value:" + TN_CMS.Framework.Helper.CommonHelper.GetFullHtmlFieldNameWithoutPrefix(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty)) }
        })
    <input type="file" name="upload@(ViewData.TemplateInfo.GetFullHtmlFieldId(string.Empty))" id="upload@(ViewData.TemplateInfo.GetFullHtmlFieldId(string.Empty))" />
    @if (hasPreview)
    {
        <img id="preview@(ViewData.TemplateInfo.GetFullHtmlFieldId(string.Empty))" src="" alt="" width="200" data-bind="attr:{src:@fullImageUrl}" />
    }
</div>
<div style="clear:both;height:10px;font-size:0px"></div>

<script type="text/javascript">
    $(function () {
        CommonHelper.Uploadify(
        "upload@(ViewData.TemplateInfo.GetFullHtmlFieldId(string.Empty))",  // id of button Upload
        "@mediaFolder",                                                     // folder
        @isImage,                                                           // is img?
        "@(ViewData.TemplateInfo.GetFullHtmlFieldId(string.Empty))",        // id of textbox ImageUrl
        "preview@(ViewData.TemplateInfo.GetFullHtmlFieldId(string.Empty))"  // imgPreviewId
    );
    });
</script>